package leetcode_周赛._2021._202105._20210523;

/**
 * @author yzh
 * @version 1.0
 * @date 2021/5/23 10:31
 * 哪种连续子字符串更长
 * 算法：字符串
 *
 */
public class _5763 {
    public static void main(String[] args) {
        System.out.println(new _5763().checkZeroOnes("111000"));
    }

    public boolean checkZeroOnes(String s) {
        int a = 0, b = 0, finA = 0, finB = 0;
        char cur = s.charAt(0);
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            if (cur == c) {
                if (c == '0') ++a;
                if (c == '1') ++b;
            } else {
                if (cur == '0') {
                    finA = Math.max(finA, a);
                    a = 0;
                    b = 1;
                } else {
                    finB = Math.max(finB, b);
                    b = 0;
                    a = 1;
                }
                cur = c;
            }
            if (i == s.length() - 1) {
                if (cur == '0') finA = Math.max(finA, a);
                else finB = Math.max(finB, b);
            }
        }
        return finB > finA;
    }

}
